package com.own.component.mybatis.injector.method;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.own.component.mybatis.em.SqlMethod;
import org.apache.ibatis.mapping.MappedStatement;

/**
 * MaxSortOrder
 *
 * @author chenxueli
 * @date 2020/9/22 9:23
 */
public class MinSortOrder extends AbstractMethod {

    public MinSortOrder() {
        super(SqlMethod.MIN_SORT_ORDER.getMethod());
    }

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        var sqlMethod = SqlMethod.MIN_SORT_ORDER;
        var sql = String.format(sqlMethod.getSql(), this.sqlFirst(), tableInfo.getTableName(), this.sqlWhereEntityWrapper(true, tableInfo), this.sqlComment());
        var sqlSource = this.languageDriver.createSqlSource(this.configuration, sql, modelClass);
        return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Integer.class);
    }
}
